import {
  getUserIndex,
  getDemandList,
  getServiceList,
  get_demand_id,
  getSimilarDemand,
  getServiceInfo,
  getShopDetail
} from "@/assets/api/service";
import {
  getpcslideshow
} from "@/assets/api/indexApi";


export const state = () => ({

  serviceHotSearch: '',

  UserIndex: null,
  lunboList: null,

  demandlist: null,
  ServiceList: null,

  DemandDetai: null,
  similarList: [],

  ServiceInfoRes: null,
  ShopDetailRes: null


})

export const getters = {
  get_serviceHotSearch: (state) => state.showInfo,
}

export const mutations = {

  set_serviceHotSearch(state, data) {
    state.serviceHotSearch = data
  },

  set_UserIndex(state, data) {
    state.UserIndex = data
  },

  set_lunboList(state, data) {
    state.lunboList = data
  },

  set_DemandList(state, data) {
    state.demandlist = data
  },

  set_ServiceList(state, data) {
    state.ServiceList = data
  },

  set_ServiceInfoRes(state, data) {
    state.ServiceInfoRes = data
  },

  set_DemandDetai(state, data) {
    state.DemandDetai = data
  },

  set_similarList(state, data) {
    state.similarList = data
  },

  set_ShopDetailRes(state, data) {
    state.ShopDetailRes = data
  },
}

export const actions = {

  async Init({
    commit,
    state
  }, params) {
    const res = await getUserIndex({});
    if (res.code == 1) {
      commit('set_UserIndex', res)
    }

    const res1 = await getpcslideshow({
      type: 9,
    });
    if (res1.code == 1) {
      commit('set_lunboList', res1)
    }
  },


  async DemandListInit({
    commit,
    state
  }, params) {
    const res = await getDemandList({
      sort: 0,
      page: 1,
      pagesize: 9,
      time_type: "0"
    });
    if (res.code == 1) {
      commit('set_DemandList', res)
    }
  },

  async DemandDetailInit({
    commit,
    state
  }, params) {
    console.log(params)
    const res = await get_demand_id({
      demand_id: params.id,
    });
    if (res.code == 1) {
      commit('set_DemandDetai', res)
    }
    const res1 = await getSimilarDemand({})
    if (res1.code == 1) {
      commit('set_similarList', res1.data)
    }
  },

  async ServiceListInit({
    commit,
    state
  }, params) {
    const res = await getServiceList({
      sort: 0,
      page: 1,
      pageSize: 10
    });
    if (res.code == 1) {
      commit('set_ServiceList', res)
    }
  },

  async ServiceInfoInit({
    commit,
    state
  }, params) {
    const res = await getServiceInfo({
      id: params.id,
      keyword: '',
      page: 1,
      pagesize: 16,
    });
    if (res.code == 1) {
      commit('set_ServiceInfoRes', res)
    }
  },

  async ServiceShopsDetailInit({
    commit,
    state
  }, params) {
    const res = await getShopDetail({
      id: params.id
    });
    if (res.code == 1) {
      commit('set_ShopDetailRes', res)
    }
  },

}
